package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/28 10:02
 */
public class LS55 {
    public boolean canJump(int[] nums) {
        if (nums.length == 1) {
            return true;
        }
        int maxLen = nums[0] + 1;

        for (int i = 1; i < nums.length; i++) {
            int index = i + 1;
            //判断能不能走下一步
            if (index <= maxLen) {
                int len = nums[i];
                //更新maxLen
                if (index + len > maxLen){
                    maxLen = index + len;
                }
                if (maxLen >= nums.length) {
                    return true;
                }
            }

        }
        return false;
    }
}
